package com.zzy.controller;

import com.alibaba.fastjson.JSON;
import com.zzy.model.AjaxMsg;
import com.zzy.model.MenuEntity;
import com.zzy.model.ParamVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/vue/")
public class TestVueController {
    private final static Logger logger = LoggerFactory.getLogger(TestVueController.class);
    // 对面直接传递参数
    @ResponseBody
    @RequestMapping("login")
    public AjaxMsg loginTest(@RequestBody ParamVO paramVO){
        logger.info("传递的参数为:"+paramVO.getUsername() + "：" +paramVO.getPassword());
        // 这里
        return AjaxMsg.returnAjaxMsg(paramVO);
    }

    @ResponseBody
    @RequestMapping("menu")
    public AjaxMsg menu(){
        //String res = "[{\"id\":\"1\",authName:\"系统设置\",children:[{\"id\":\"1-1\",authName:\"选项一\",\"path\":\"/seting1\"},{\"id\":\"1-2\",authName:\"选项二\",children:[{\"id\":\"1-2-1\",authName:\"选项2-1\",\"path\":\"/seting1\"}]}]},{\"id\":\"2\",authName:\"订单管理\"}]";
        List<MenuEntity> list = new ArrayList<>();
        MenuEntity menu1 = new MenuEntity("1","系统管理","","el-icon-setting");
        List<MenuEntity> l1 = new ArrayList<>();
        l1.add(new MenuEntity("1-1","用户管理","users","el-icon-user-solid"));
        l1.add(new MenuEntity("1-2","通用配置","setting","el-icon-s-tools"));
        l1.add(new MenuEntity("1-3","测试iview","iview","el-icon-s-tools"));
        menu1.setChildren(l1);

        MenuEntity menu2 = new MenuEntity("2","订单管理","","el-icon-goods");
        List<MenuEntity> l2 = new ArrayList<>();
        l2.add(new MenuEntity("2-1","待付款","waitting","el-icon-s-promotion"));
        l2.add(new MenuEntity("2-2","已完成订单","complete","el-icon-check"));
        menu2.setChildren(l2);

        MenuEntity menu3 = new MenuEntity("3","报表","","el-icon-s-data");
        List<MenuEntity> l3 = new ArrayList<>();
        l3.add(new MenuEntity("3-1","测试报表","report","el-icon-s-finance"));
        menu3.setChildren(l3);


        list.add(menu1);
        list.add(menu2);
         list.add(menu3);
         logger.info(JSON.toJSONString(list));
         return AjaxMsg.returnAjaxMsg(list);
    }

}
